package org.jeecg.modules.user.member.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.client.GetuiPush;
import org.jeecg.modules.constant.BikeConstant;
import org.jeecg.modules.user.member.dto.*;
import org.jeecg.modules.user.member.entity.Member;
import org.jeecg.modules.user.member.service.MemberService;
import org.jeecg.modules.utils.BikeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;

/**
* @Description: bike_pile
* @Author: jeecg-boot
* @Date:   2021-05-19
* @Version: V1.0
*/
@Api(tags="注册")
@RestController
    @RequestMapping("/app/member")
@Slf4j
public class MemberController extends JeecgController<Member, MemberService> {
   @Autowired
   private MemberService memberService;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private GetuiPush getuiPush;
   /**
    *   添加
    *
    * @param member
    * @return
    */
   @ApiOperation(value="注册", notes="注册")
   @PostMapping(value = "/add")
   public BikeResult add(@RequestBody Member member) {
      return memberService.insertMenberUser(member);
       //return BikeResult.error("0","功能暂未开放，敬请期待！",null);
   }

    /**
     * 添加clientId
     *
     * @param clientId 设备id
     * @param phone    手机号
     * @param type     1 安卓 2 ios
     * @return
     */
    @ApiOperation(value = "添加clientId", notes = "添加clientId")
    @PostMapping(value = "/addClientId")
    public BikeResult addClientId(@RequestParam(name = "clientId") String clientId, @RequestParam(name = "phone") String phone, @RequestParam(name =
            "type") String type) {
        if (StringUtils.isEmpty(clientId)||StringUtils.isEmpty(phone)||StringUtils.isEmpty(type)){
            return BikeResult.error("0","请确保参数正确"+clientId+"+"+phone+"+"+type,null);
        }
        redisUtil.set(BikeConstant.client_id_prefix + phone, clientId);
        redisUtil.set(BikeConstant.client_id_prefix + "type" + phone, type);
        return BikeResult.ok("1", "添加成功", null);
    }
    /**
     *   测试UniPush
     * @return
     */
    @ApiOperation(value="测试UniPush", notes="测试UniPush")
    @PostMapping(value = "/testUniPush")
    public BikeResult testUniPush(@Param(value =  "transmission") String transmission,@Param(value = "phone") String phone) {
        getuiPush.PushMsg(phone,transmission);
        return BikeResult.ok("1","测试成功",null);
    }
    /**
     *   账号密码登录
     *
     * @param
     * @return
     */
    @ApiOperation(value="账号密码登录", notes="账号密码登录")
    @PostMapping(value = "/login")
    public BikeResult appLogin(@RequestBody LoginsReq loginsReq) {
        return memberService.appLogin(loginsReq);
    }

    /**
     *   手机号码登录
     *
     * @param
     * @return
     */
    @ApiOperation(value="手机号码登录", notes="手机号码登录")
    @PostMapping(value = "/phoneLogin")
    public BikeResult phoneLogin(@RequestBody LoginPhoneReq loginPhoneReq) {
        return memberService.phoneLogin(loginPhoneReq);
    }


    /**
     *   忘记密码
     *
     * @param
     * @return
     */

    @ApiOperation(value="忘记密码", notes="忘记密码")
    @PostMapping(value = "/forgetPassword")
    public BikeResult forgetPassword(@RequestBody ForgetPasswordReq forgetPasswordReq) {
        return memberService.forgetPassword(forgetPasswordReq);
    }

    /**
     *   修改用户信息
     *
     * @param
     * @return
     */
    @ApiOperation(value="修改用户信息", notes="修改用户信息")
    @PostMapping(value = "/updateMember")
    public BikeResult updateMember(@RequestBody MemberReq memberReq) {
        return memberService.updateMember(memberReq);
    }

    /**
     *   换绑手机号1
     *
     * @param
     * @return
     */
    @ApiOperation(value="换绑手机号1", notes="换绑手机号1")
    @PostMapping(value = "/checkPhone")
    public BikeResult checkPhone(@RequestBody LoginPhoneReq loginPhoneReq) {
        return memberService.checkPhone(loginPhoneReq);
    }

    /**
     *   换绑手机号2
     * @param
     * @return
     */
    @ApiOperation(value="换绑手机号2", notes="换绑手机号2")
    @PostMapping(value = "/updatePhone")
    public BikeResult updatePhone(@RequestBody LoginPhoneReq loginPhoneReq, HttpServletRequest request) {
        return memberService.updatePhone(loginPhoneReq,request);
    }

    @ApiOperation(value = "我的行程", notes = "我的行程")
    @RequestMapping(value = "/getTripList", method = RequestMethod.POST)
    public BikeResult getTripList(@RequestBody MemberIdReq memberIdReq, HttpServletRequest request){
        return memberService.getTripList(memberIdReq,request);
    }

    @ApiOperation(value = "退出登录", notes = "退出登录")
    @RequestMapping(value = "/appLogOut", method = RequestMethod.POST)
    public BikeResult appLogOut(HttpServletRequest request){
        return memberService.appLogOut(request);
    }

    @ApiOperation(value = "注销", notes = "注销")
    @RequestMapping(value = "/appLogOff", method = RequestMethod.POST)
    public BikeResult appLogOff(HttpServletRequest request){
        return memberService.appLogOff(request);
    }

    @ApiOperation(value = "余额明细", notes = "余额明细")
    @RequestMapping(value = "/detailed", method = RequestMethod.GET)
    public BikeResult detailed(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize, HttpServletRequest request){
        return memberService.detailed(pageNum,pageSize,request);
    }

    @ApiOperation(value = "修改密码", notes = "修改密码")
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    public BikeResult updatePassword(@RequestBody MemberPwdReq memberPwdReq, HttpServletRequest request){
        return memberService.updatePassword(memberPwdReq,request);
    }


}
